#!/usr/bin/env bash

keeplived_config(){
  echo "生成kepplived配置文件"
  cat > /etc/keepalived/keepalived.conf << EOF
global_defs {
   router_id LVS_k8s
}

vrrp_script checkhaproxy
{
    script "/etc/keepalived/check_nginx.sh"
    interval 5
}

vrrp_instance VI_1 {
    # 注意主备参数选择
    state ${state}
    # 改成本机网卡名 例如 eth0
    interface ${ETH_INT}
    virtual_router_id 61
    # 非抢占模式
    nopreempt
    # 主高于备, 例如 主 50，备 30
    priority ${priority}
    advert_int 1
    authentication {
    auth_type PASS
    auth_pass awzhXylxy.T
    }
    # 本机内网 IP
    unicast_src_ip ${hostip}
    unicast_peer {
    # 注释掉本地IP
    ${IPS}
    }
    # 内网 VIP
    virtual_ipaddress {
    ${VIP}
    }
    notify_master "/etc/keepalived/notify_action.sh MASTER"
    notify_backup "/etc/keepalived/notify_action.sh BACKUP"
    notify_fault "/etc/keepalived/notify_action.sh FAULT"
    notify_stop "/etc/keepalived/notify_action.sh STOP"
    garp_master_delay 1
    garp_master_refresh 5
    #改成本机网卡名 例如 eth0
    track_interface {
       ${ETH_INT}
    }
    track_script {
    checkhaproxy
    }
}
EOF
}

keeplived_init(){
 echo "这是我第一个shell函数"
    rerurn 1
}



